<?php
class Login extends MY_Controller {
	var $caption = "";
	var $currentPage = 'login';
	var $action = '';
	
		public function index(){
			$data = '';
			$found = false;
			if(isset($_REQUEST['username'])&&isset($_REQUEST['password'])){
				$username  = $_REQUEST['username'];
				//$password  = $_REQUEST['password'];
				$password  = crypt($_POST['password'],PASSWORDSALT);
				$checkUser = $this->db->query("select * from user where  username = '$username' and password = '$password' and activated = 1 and usertype = 'CLIENT' limit 1");
			
			 	//echo "select * from user where  username = '$username' and password = '$password' and activated = 1 and usertype = 'CLIENT' limit 1";
			
				if($checkUser->row() != null){
					$this->session->set_userdata('client_id', $checkUser->row()->id);
					$this->session->set_userdata('client_fullname', $checkUser->row()->firstname." ".$checkUser->row()->middlename." ".$checkUser->row()->lastname);
					$this->session->set_userdata('client_email', $checkUser->row()->email);
					$this->session->set_userdata('client_type', $checkUser->row()->usertype);
					$this->caption = "Dashboard";
					//echo "LOGGED";
					$this->page("");
					$found = true;
					
					
					if(isset( $_POST['dealId'])){
						$deal = $_POST['dealId'];
						redirect(DEALURL.'\view\\'.$deal);
					}
				}
				else{
					//echo "NOT LOGGED";
				}
			}

			$data = $_POST;
			$data['page_was_found'] = false;
			$data['categorydeallist'] = $this->mDealCategory->getAllEntries();
			
			//related to deals
			$page = "login";
			$data['page'] = $page;
			
			if(! $found)
				$this->page($page, $data);
		
	}
	
	

	


}